package com.seckill.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seckill.exception.GlobalException;
import com.seckill.mapper.UserMapper;
import com.seckill.pojo.User;
import com.seckill.service.IUserService;
import com.seckill.utils.MD5Util;
import com.seckill.utils.ValidatorUtil;
import com.seckill.vo.LoginVO;
import com.seckill.vo.RespBean;
import com.seckill.vo.RespBeanEnum;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsh
 * @since 2025-06-01
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public RespBean doLogin(LoginVO loginVO) {
        String mobile = loginVO.getMobile();
        String password = loginVO.getPassword();

        User user = userMapper.selectById(mobile);
        if(null == user) {
            throw new GlobalException(RespBeanEnum.LOGIN_ERROR);
        }
        if(!MD5Util.formPassToDBPass(password, user.getSlat()).equals(user.getPassword())) {
            throw new GlobalException(RespBeanEnum.LOGIN_ERROR);
        }

        return RespBean.success("登录成功");
    }
}
